package com.wanrue.tcc.context;


import lombok.Data;

import java.io.Serializable;
import java.util.UUID;

/**
 * xid 的实现
 * Created by wenjie on 11/08/18.
 */
@Data
public class Xid implements Serializable {

    private static final long serialVersionUID = -6817267250789142043L;
    /**
     * xa 全局事务id
     */
    private String globalTransactionId;

    /**
     * xa 分支限定符
     */
    private String branchQualifier;

    public Xid() {
        this.globalTransactionId = UUID.randomUUID().toString().replace("-", "");
        this.branchQualifier = UUID.randomUUID().toString().replace("-", "");
    }

    public Xid(String globalTransactionId) {
        this.globalTransactionId = globalTransactionId;
        this.branchQualifier = UUID.randomUUID().toString().replace("-", "");
    }

    public Xid(String globalTransactionId, String branchQualifier) {
        this.globalTransactionId = globalTransactionId;
        this.branchQualifier = branchQualifier;
    }

    @Override
    public String toString() {
        return globalTransactionId + ":" + branchQualifier;
    }
}


